home *** CD-ROM | disk | FTP | other *** search
- /*
- ------ T H E W I N D O W P R O C E D U R E
-
- May 1989 - HA OLIVER
-
- */
-
- #include "Demo.h"
-
-
- extern Rect dragRect,growRect;
- extern TEHandle CurrentText;
- extern ListHandle CurrentList;
- extern WindowPtr CurrentPort;
- extern Handle ListList,TextList,PictList;
- extern Boolean isDoc;
- extern int dh,dv;
- static WindowPtr theWindow;
- static EventRecord theEvent;
-
-
- /*
- ------------- Grow
- */
-
- DoGrow()
- {
- }
-
- /*
- ---------------------- mouseDown is in "theWindow" ...
- */
-
- TestInContent(global)
- Point global;
- {
- Point newOr,local;
- Rect contRect;
- char result;
- TEHandle theText;
- ListHandle theList;
- int inControlPart;
- ControlHandle theControl;
- PicHandle thePic;
-
- local=global;
- GetWindowClip(&contRect,&newOr,theWindow);
- SetOrigin(0,0);
- GlobalToLocal(&local);
- ClipRect(&(*theWindow).portRect);
-
- if (PtInRect(local,&contRect))
- {
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- local=global;
- GlobalToLocal(&local);
-
- theText=FindText(local,theWindow);
- if (theText!=NULL)
- { if (theText!=CurrentText)
- { if (CurrentText!=NULL) TEDeactivate(CurrentText);
- TEActivate(theText);
- CurrentText=theText;
- }
- if (CurrentList!=NULL) LActivate(false,CurrentList);
- CurrentList=NULL;
- TEClick(local,false,CurrentText);
- }
- else
- {
- theList=FindList(true,local,theWindow);
- if (theList!=NULL)
- { if (theList!=CurrentList)
- { if (CurrentList!=NULL) LActivate(false,CurrentList);
- LActivate(true,theList);
- CurrentList=theList;
- }
- if (CurrentText!=NULL) TEDeactivate(CurrentText);
- CurrentText=NULL;
- result =LClick(local,theEvent.modifiers,CurrentList);
- }
- else
- {
- inControlPart=FindControl(local,theWindow,&theControl);
- if (theControl!=NULL)
- {
- if (CurrentList!=NULL) LActivate(false,CurrentList);
- CurrentList=NULL;
- if (CurrentText!=NULL) TEDeactivate(CurrentText);
- CurrentText=NULL;
-
- switch(inControlPart)
- {
- case inButton :if (TrackControl(theControl,local,NULL)!=0)
- ExecControl(theControl);break;
- case inCheckBox :if (TrackControl(theControl,local,NULL)!=0)
- {
- switch(GetCtlValue(theControl))
- {
- case 1:SetCtlValue(theControl,0);break;
- case 0:SetCtlValue(theControl,1);break;
- }
- ExecControl(theControl);
- };break;
- case inUpButton :
- case inDownButton:
- case inPageDown :
- case inPageUp :
- case inThumb :
- default :break;
-
- }
- }
- else
- {
- if (CurrentList!=NULL) LActivate(false,CurrentList);
- CurrentList=NULL;
- if (CurrentText!=NULL) TEDeactivate(CurrentText);
- CurrentText=NULL;
-
- thePic=FindPict(local,theWindow);
- if(thePic!=NULL)
- {
- SysBeep(5);
- }
- }
- }
- }
- SetCurrents(CurrentText,CurrentList,theWindow);
-
- }
- }
-
- /*
- ---------------------- mouseDown on the desktop ...
- */
-
-
- DoMouseDown()
- {
- switch(FindWindow(theEvent.where,&theWindow))
- {
- case inContent :if (theWindow!=FrontWindow())
- SelectWindow(theWindow);
- else TestInContent(theEvent.where);
- break;
-
- case inGoAway :if (TrackGoAway(theWindow,theEvent.where))
- {
- DeInstalWindow(theWindow);
- CurrentText=NULL;
- CurrentList=NULL;
- if (FrontWindow()==NULL) isDoc=FALSE;
- };
- break;
-
- case inGrow :if (theWindow!=FrontWindow())
- SelectWindow(theWindow);
- else if (WindowWithGrow(theWindow)) DoGrow();
- break;
- case inDrag :DragWindow(theWindow,theEvent.where,&dragRect);break;
- case inZoomIn :
- case inZoomOut :break;
- }
- }
-
- /*
- ---------------------- A key Down...
- */
-
-
- DoKeyDown()
- {
- Rect contRect;
- Point newOr;
- register char key;
-
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- key =theEvent.message & charCodeMask;
- if (CurrentText!=NULL) TEKey(key,CurrentText);
- if (CurrentList!=NULL)
- {
- ObscureCursor();
- ListKey(key,CurrentList);
- }
- }
-
- /*
- ---------------------- Update the Window
- */
-
- DoUpdate()
- {
- Rect contRect;
- Point newOr;
-
- BeginUpdate(theWindow);
- EraseRect(&(*theWindow).portRect);
- SetOrigin(0,0);
- ClipRect(&(*theWindow).portRect);
- if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- DrawPicts(theWindow);
- DrawTexts(theWindow);
- DrawLists(theWindow);
- DrawControls(theWindow);
- EndUpdate(theWindow);
- }
-
- /*
- ---------------------- Activate the Window
- */
-
- DoActivate()
- {
- Rect contRect;
- Point newOr;
-
- if (theEvent.modifiers & activeFlag)
- {
- SetOrigin(0,0);
- ClipRect(&(*theWindow).portRect);
- HiliteAllControls(CtlActive,theWindow);
- if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- ActivateText(theWindow);
- ActivateList(theWindow);
- }
- else
- {
- SetOrigin(0,0);
- ClipRect(&(*theWindow).portRect);
- HiliteAllControls(CtlInactive,theWindow);
- if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- DeactivateText(theWindow);
- DeactivateList(theWindow);
- }
- }
-
- /*
- ----------------------
- */
-
- DoNullEvent()
- {
- }
-
- /*
- ---------------------- Resume or Suspend needed...
- */
-
- DoMulti()
- {
- Rect contRect;
- Point newOr;
-
- if (theEvent.message & 1)
- {
- SetOrigin(0,0);
- ClipRect(&(*theWindow).portRect);
- HiliteAllControls(CtlActive,theWindow);
- if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- ActivateText(theWindow);
- ActivateList(theWindow);
- }
- else
- {
- SetOrigin(0,0);
- ClipRect(&(*theWindow).portRect);
- HiliteAllControls(CtlInactive,theWindow);
- if (WindowWithGrow(theWindow)) DrawGrowIcon(theWindow);
- GetWindowClip(&contRect,&newOr,theWindow);
- OffsetRect(&contRect,newOr.h,newOr.v);
- ClipRect(&contRect);
- SetOrigin(newOr.h,newOr.v);
- DeactivateText(theWindow);
- DeactivateList(theWindow);
- }
- }
-
- /*
- ---------------------- This Function is called when
- an Event occurs for "theWindow"
- */
-
- pascal void MyWindow(anEventAdd,inWindow)
- EventRecord *anEventAdd;
- WindowPtr inWindow;
- {
-
- theWindow = inWindow;
- theEvent = *anEventAdd;
- GetPort(&CurrentPort);
- SetPort(theWindow);
- switch(theEvent.what)
- {
- case nullEvent :DoNullEvent();break;
- case mouseDown :DoMouseDown();break;
- case mouseUp :break;
- case keyDown :DoKeyDown();break;
- case keyUp :break;
- case autoKey :DoKeyDown();break;
- case updateEvt :DoUpdate();break;
- case activateEvt :DoActivate();break;
- case diskEvt :break;
- case multiFinderEvt:DoMulti();break;
-
- default:break; /* HighLevelEvent ? */
- }
- SetPort(CurrentPort);
- }
-
- /*
- ---------------------
- */